package com.tjsinfo.tjsoa.vote.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;

import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.common.PaginationSupport;
import com.tjsinfo.tjsoa.vote.vo.TVoteHead;

public class HeadListAction extends Action {
	private IQbcDao qbcDao;	

	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(TVoteHead.class);
		//criteria.add(Restrictions.eq("userId", String.valueOf(ToolKit.getSessionUser(request).getUser_id())));
		List<Order> orderList=new ArrayList<Order>();
		orderList.add(Order.desc("yearTime"));
		
		Integer pageSize=12;
		String pageStr=request.getParameter("pageNo");
		if(pageStr==null)pageStr="0";
		int page=Integer.valueOf(pageStr).intValue();
		int startIndex=pageSize*page;
		PaginationSupport paginationSupport=qbcDao.findPageByCriteria(criteria,orderList, Integer.valueOf(pageSize),startIndex);
		request.setAttribute("paginationSupport", paginationSupport);	
		
		return mapping.findForward("success");
	}
}